home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Extension Shell 1.3 Folder / Extension Shell 1.3 ƒ / Sample Extensions / Shutdown Fade ƒ / Shutdown Fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  6.9 KB  |  276 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         Shutdown Fade.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a CODE resource to be used as a handler by
  9.         Extension Shell.
  10.  
  11.     NOTES:
  12.         •    Animates a sequence of icons.
  13.  
  14.     ___________________________________________________________________________
  15.  
  16.     VERSION HISTORY:
  17.         (Jan 1994, dg)
  18.             •    First publicly distributed version.
  19.  
  20.  
  21.     ___________________________________________________________________________
  22. */
  23. //=============================================================================
  24. //        Include files                                                                     
  25. //-----------------------------------------------------------------------------
  26. #include <Shutdown.h>
  27. #include "Shutdown Fade.h"
  28. #include "ParamBlock.h"
  29. #include "StandaloneCode.h"
  30. #include "ESConstants.h"
  31. #include "CodeConstants.h"
  32.  
  33.  
  34.  
  35.  
  36.  
  37. //=============================================================================
  38. //        Private function prototypes                                                                     
  39. //-----------------------------------------------------------------------------
  40. void    main(short theMsg, ESParamBlock *theParamBlock);
  41. void    InitialiseParamBlock(void);
  42. void    InitialiseAddrsTable(void);
  43. void    HandleTheError(void);
  44. void    SetUpIcons(int animDelay, int numIcons, int firstIcon);
  45.  
  46.  
  47.  
  48.  
  49.  
  50. //=============================================================================
  51. //        Global variables                                                                 
  52. //-----------------------------------------------------------------------------
  53. ESParamBlock    *gTheParamBlock;
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. //=============================================================================
  65. //        main : Entry point to our code resource.                                                                 
  66. //-----------------------------------------------------------------------------
  67. //        Note :    Extension Shell communicates with us via a message constant,
  68. //                and a pointer to a structure it owns. Our job is to fill in
  69. //                the details, depending on what it wants us to do. It takes
  70. //                care of the rest.
  71. //-----------------------------------------------------------------------------
  72. void main(short theMsg, ESParamBlock *theParamBlock)
  73. {
  74.  
  75.  
  76.  
  77.  
  78.     // Set up A4 so that we can access our globals, and initialise them.
  79.     GetGlobals();
  80.     gTheParamBlock = theParamBlock;
  81.  
  82.  
  83.  
  84.     // Case out on what we have to do
  85.     switch(theMsg) {
  86.         case kInitialiseParamBlock:
  87.              InitialiseParamBlock();
  88.              break;
  89.              
  90.         case kInitialiseAddrsTable:
  91.              InitialiseAddrsTable();
  92.              break;
  93.  
  94.         case kHandleError:
  95.              HandleTheError();
  96.              break;
  97.     
  98.         default:
  99.              ;
  100.     }
  101.  
  102.  
  103.  
  104.     // Restore A4.
  105.     UngetGlobals();
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. //=============================================================================
  118. //        InitialiseParamBlock : Initialises the ParamBlock.                                                                 
  119. //-----------------------------------------------------------------------------
  120. //        Note :    We have three things we want to do:
  121. //                    • Check to see if we can still run
  122. //                    • Set up the icons we want to display
  123. //                    • Set up the code we want installed
  124. //-----------------------------------------------------------------------------
  125. void InitialiseParamBlock(void)
  126. {    int        i;
  127.  
  128.  
  129.  
  130.  
  131.     // Check for System 7. We depend on having System 7, and won't
  132.     // run if we don't have it. We beep, post an error message,
  133.     // and show our disabled icon(s).
  134.     if (gTheParamBlock->systemVersion < 0x0700)
  135.         {
  136.         // Error details
  137.         gTheParamBlock->beepNow                = true;
  138.         gTheParamBlock->postError            = true;
  139.         gTheParamBlock->errorStringsID        = kErrorStrings;
  140.         gTheParamBlock->errorStringIndex    = kNeedSystemSeven;
  141.  
  142.  
  143.         // Icon details
  144.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  145.         }
  146.     
  147.     
  148.     
  149.     // If a shift key, or the mouse button, is down, we don't load either.
  150.     // We don't post an error, but we do show our disabled icon(s).
  151.     else if ((*gTheParamBlock->UserForcedDisable)(kShiftKey, true))
  152.         {
  153.         // Icon details
  154.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  155.         }
  156.     
  157.     
  158.     
  159.     // Otherwise, we're allowed to run so we show our icon(s) as normal,
  160.     // and fill in the details for the code we want installed.
  161.     else
  162.         {
  163.         // Icon details
  164.         SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
  165.         
  166.         
  167.         // We install one Shutdown task, with no address table.
  168.         gTheParamBlock->installAddressTable        = false;
  169.         gTheParamBlock->numCodeResources        = 1;
  170.  
  171.  
  172.         // Details for a Shutdown task
  173.         gTheParamBlock->theCodeResources[kShutdownFade].resType        = kFadeResType;
  174.         gTheParamBlock->theCodeResources[kShutdownFade].resID        = kFadeResID;
  175.         gTheParamBlock->theCodeResources[kShutdownFade].codeType    = kShutdownTaskType;
  176.         gTheParamBlock->theCodeResources[kShutdownFade].theCodeThing.theShutdownTask.theFlags = sdOnPowerOff;
  177.         }
  178. }
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189. //=============================================================================
  190. //        InitialiseAddrsTable : Initialise the address table.                                                     
  191. //-----------------------------------------------------------------------------
  192. //        Note :    If we are being used in a Control Panel, we will probably have
  193. //                implemented the address table code with a custom code resource
  194. //                that returns a structure with an address table embedded at the
  195. //                start. This function's job is to correctly initialise the
  196. //                extended fields of that structure. If we're not using a
  197. //                (custom) address table then we don't do anything.
  198. //
  199. //                The message for this routine will only arrive if we've
  200. //                requested an address table.
  201. //-----------------------------------------------------------------------------
  202. void InitialiseAddrsTable(void)
  203. {
  204.  
  205.  
  206.  
  207. }
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218. //=============================================================================
  219. //        HandleTheError : Handle any errors                                                             
  220. //-----------------------------------------------------------------------------
  221. //        Note :    If any error occurs, we beep, post an error, and remove our
  222. //                code. We also have to reset the icon details to show our
  223. //                disabled icons.
  224. //-----------------------------------------------------------------------------
  225. void HandleTheError(void)
  226. {
  227.  
  228.  
  229.  
  230.  
  231.     // General error handling settings
  232.     gTheParamBlock->removeInstalledCode    = true;
  233.     gTheParamBlock->beepNow                = true;
  234.     gTheParamBlock->postError            = true;
  235.     gTheParamBlock->errorStringsID        = kErrorStrings;
  236.  
  237.  
  238.  
  239.     // Icon details
  240.     SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  241.  
  242.  
  243.  
  244.     // Just give a general error.
  245.     gTheParamBlock->errorStringIndex = kUnknownError;
  246. }
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. //=============================================================================
  258. //        SetUpIcons : Set up our icons accordingly.                                                         
  259. //-----------------------------------------------------------------------------
  260. //        Note :    We are passed in the resource ID of the first icon, the number
  261. //                of icons, and a delay for animation. We just fill in the fields
  262. //                in the paramBlock.
  263. //-----------------------------------------------------------------------------
  264. void SetUpIcons(int animDelay, int numIcons, int firstIcon)
  265. {    int        i;
  266.  
  267.  
  268.  
  269.  
  270.     // Fill in the fields
  271.     gTheParamBlock->animationDelay    = animDelay;
  272.     gTheParamBlock->numIcons        = numIcons;
  273.     for (i = 1; i <= numIcons; i++)
  274.         gTheParamBlock->theIcons[i] = firstIcon + i - 1;
  275. }
  276.